package com.atguigu.controller;

import com.atguigu.bean.Employee;
import com.atguigu.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    @GetMapping("/emps")
    public List<Employee> getEmps() {
        return employeeService.getEmps();
    }

    @GetMapping("/emp/{id}")
    public Employee getEmpById(@PathVariable("id") Integer id) {
        return employeeService.getEmpById(id);
    }

    @RequestMapping("/emp/add")
    public Employee addEmp(Employee emp) {
        employeeService.addEmp(emp);
        return emp;
    }

    @RequestMapping("/emp/edit")
    public Employee editEmp(Employee emp) {
        employeeService.editEmp(emp);
        return emp;
    }

    @RequestMapping("/emp/delete/{id}")
    public int deleteEmp(@PathVariable("id") Integer id) {
        return employeeService.deleteEmp(id);
    }

    @RequestMapping("/emp/name/{name}")
    public Employee getEmpByName(@PathVariable("name") String name) {
        return employeeService.getEmpByName(name);
    }
}
